﻿using System;
using System.Data;

using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client;
//using Oracle.DataAccess.Types;

using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Oracle;

namespace DBQuery
{
    /// <summary>
    /// Summary description for EmailSenderTable
    /// </summary>
    public static class EmailSenderTable
    {
        public static String GetRecentEmail()
        {
            DBLib dbl = new DBLib();
 
            String sxQuery =
                @"
                select
                    EMAIL
                from
                    T_EMAIL_SENDER
                where
                    NVL(VALID_TO,sysdate+1) > sysdate
                ";
            String sxOutput = String.Empty;
            String sxEmail = String.Empty;
            sxEmail = dbl.GetSingleValue(sxQuery).ToString();
            if (!String.IsNullOrEmpty(sxEmail))
            {
                sxOutput = sxEmail;
            }
            return sxOutput;
        }
        public static int NewEmailSender(String sxNewEmail)
        {
            DBLib dbl = new DBLib();

            OracleParameter prmID = new OracleParameter();
            prmID.ParameterName = "out_new_id";
            prmID.OracleDbType = OracleDbType.Number;
            prmID.Direction = ParameterDirection.Output;

            OracleParameter prmEmail = new OracleParameter();
            prmEmail.ParameterName = "in_EMAIL";
            prmEmail.OracleDbType = OracleDbType.VarChar;
            prmEmail.Value = sxNewEmail;

            OracleParameter prmCreateBy = new OracleParameter();
            prmCreateBy.ParameterName = "in_CREATE_BY";
            prmCreateBy.OracleDbType = OracleDbType.VarChar;
            prmCreateBy.Value = ICPUser.ID;

            String sxQuery = "pr_insert_email_sender";

            dbl.ExecuteProcedure(sxQuery, prmID, prmEmail, prmCreateBy);

            return Convert.ToInt32(prmID.Value);
        }
        public static void UpdateOldEmail(int iOldEmailID)
        {
            DBLib dbl = new DBLib();

            OracleParameter prmID = new OracleParameter();
            prmID.ParameterName = "prmID";
            prmID.OracleDbType = OracleDbType.Number;
            prmID.Value = iOldEmailID;

            String sxQuery =
            @"
            update
                T_EMAIL_SENDER
            set
                VALID_TO = Sysdate
            where
                T_EMAIL_SENDER_ID = :prmID
            ";
            dbl.ExecuteNonQuery(sxQuery, prmID);
        }
    }
}